<?php

class CLogFile extends CBase implements ILog {
	
	function __construct()
	{
		
	}
	
	public function write($content,$dir=null,$fileName=null)
	{
		if(!$dir)
		{
			$dir=Config::get("log.logDir","");
		}

		if(!$dir)
		{
			CError::handler(E_ERROR,"请设置日志目录",__FILE__,__LINE__);
		}
		
		if(!is_dir($this->_basePath.$dir))
		{
			CUtil::createFolder($this->_basePath.$dir);
		}

		if(!$fileName)
		{
			$fileName = date("Y-m-d").".txt";
		}
		
		$fileName = $this->_basePath.$dir.DIRECTORY_SEPARATOR.$fileName;
		
		$fHandler=@fopen($fileName, "a+");
		
		if($fHandler)
		{
			$content = "============".date("Y-m-d H:i:s")."============".PHP_EOL.$content."========================".PHP_EOL.PHP_EOL;
			fwrite($fHandler,$content);
			
			fclose($fHandler);
		}
		else
		{
			CError::handler(E_WARNING,"打开文件".$fileName."失败.",__FILE__,__LINE__);
		}
	}
}

?>